package com.example.thinkandroid;

import com.example.util.Util;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.LinearLayout;

public class Main extends Activity {

	public Util util = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		util = new Util(getApplicationContext());
		requestWindowFeature(Window.FEATURE_NO_TITLE);//不显示当前界面标题栏
		
        final View view = View.inflate(this, R.layout.main, null);
        view.setBackgroundResource(R.drawable.vpic); //设置背景图片，这里可以先判断当前是否为横屏，如果横屏则显示hpic
        setContentView(view);
        
		//渐变展示启动屏
		AlphaAnimation aa = new AlphaAnimation(0.3f,1.0f);
		aa.setDuration(2000);
		view.startAnimation(aa);
		aa.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationEnd(Animation arg0) {
				redirectTo();
			}
			@Override
			public void onAnimationRepeat(Animation animation) {}
			@Override
			public void onAnimationStart(Animation animation) {}
			
		});	
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		getMenuInflater().inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onMenuOpened(int featureId, Menu menu) {
		// TODO Auto-generated method stub
		Log.d("LOG", "opened:" + featureId);
		Log.d("LOG", "菜单个数:" + menu.size());
		util.alert("菜单开始启用");
		return super.onMenuOpened(featureId, menu);
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case R.id.ic_actbar_mail:
			util.alert("菜单1:" + item.toString());
			break;
		case R.id.ic_actbar_notification:
			util.alert("提醒名称:" + item.toString());
			break;
		}
		return true;
	}
    /**
     * 跳转到...
     */
    private void redirectTo(){        
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }	

}
